clear all
use EgeEfeRefugeeRaw.dta

*Data Management*
recode z05 (99=.) (1 2 3 7 90=0) (4 5 6=1), gen(employed)
recode b1001 (1=4) (2=3) (3=2) (4=1) (98 99=.), gen(disckurd)
recode e0301 (98 99=.), gen(newspaper)
recode e0302 (98 99=.), gen(tv)
recode e0303 (98 99=.), gen(socmedia)
gen alone=1 if t03==1
replace alone=0 if t03==2
factor newspaper tv socmedia, pcf
rotate, varimax
predict media

recode a01 (98 99=.), gen(egocentsatis)
recode a02 (98 99=.), gen(sociotrop)

recode t01 (2 3=0), gen(urban)

gen istanbul=1 if il==34
replace istanbul=0 if il<34

gen diyarbakir=1 if il==21
replace diyarbakir=0 if il>21

gen antep=1 if il==27
replace antep=0 if il<27
replace antep=0 if il>27

replace b03=. if b03>5
gen natidprio=1 if b03==2
replace natidprio=0 if b03>2
replace natidprio=0 if b03<2
replace natidprio=. if b03==.
gen relidprio=1 if b03==1
replace relidprio=0 if b03>1
replace relidprio=. if b03==.
gen ethidprio=1 if b03==3
replace ethidprio=0 if b03>3
replace ethidprio=0 if b03<3
replace ethidprio=. if b03==.

///Ethnicity 
gen turk = . 
replace turk = 1 if b01 == 1
replace turk = 0 if b01 > 1
replace turk = . if b01 > 97
gen kurd = .
replace kurd = 1 if b01 == 2 
replace kurd = 0 if b01 < 2
replace kurd = 0 if b01 > 2 
replace kurd = . if b01 > 97

///Perception of Discrimination 
replace b09 = . if b09 > 2
replace b09 = 0 if b09 == 2
rename b09 selfdiscrimination 

///Perception of State Discrimination 
replace b1001 = . if b1001 > 4 
rename b1001 discriminationkurd
replace b1002 = . if b1002 > 4
rename b1002 discrimnationturk

///Perception of Discrimination towards Kurds
replace b11 = . if b11 > 10
rename b11 perceiveddiscriminationkurd

///Attitudes toward Refugees 

///Are refugees a threat to national security? (positive --> negative)
replace d0801 = . if d0801 > 5
rename d0801 immthreat1 

///Are refugees a threat to national economy? (positive --> negative)
replace d0802 = . if d0802 > 5
rename d0802 immthreat2

///Are refugees a threat to Turkey's citizens' welfare or well-being? (positive --> negative)
replace d0803 = . if d0803 > 5
rename d0803 immthreat3

///Turkey should accept all of the immigrants (refugees). (negative --> positive)
replace d0804 = . if d0804 > 5
rename d0804 immpol1 

///Turkey should provide working permits to all of the immigrants (refugees). (negaitve --> positive)
replace d0805 = . if d0805 > 5
rename d0805 immpol2

///Turkey should give citizenship to all of the immigrants (refugees). (negative --> positive)
replace d0806 = . if d0806 > 5
rename d0806 immpol3 

///Voting (November 1st, 2015 General Elections) AKP = 1; CHP = 2; HDP = 3; MHP = 4
replace e01 = . if e01 > 4
rename e01 vote2015 

///Voting (In case there would be an election tomorrow, which political party...) AKP = 1; CHP = 2; HDP = 3; MHP = 4 
replace e02 = . if e02 > 4
rename e02 votetoday

***Ethnocentrism
recode b0601 b0602 b0701 b0702 b0801 b0802 b04 (98 99=.)
factor b0601 b0602 b0701 b0702 b0801 b0802 b04 if kurd==1, pcf
rotate, varimax
predict proturk prokurd
gen ethnokurd=prokurd-proturk
factor b0601 b0602 b0701 b0702 b0801 b0802 b04 if turk==1, pcf
rotate, varimax
predict proturk2 prokurd2
gen ethnoturk=proturk2-prokurd2
gen ethnocent= ethnoturk if turk==1
replace ethnocent= ethnokurd if kurd==1

///Demographics 

///Religiosity (self-perception)
replace z01 = . if z01 > 10
rename z01 religious 

///Religiosity (Behavior)
replace z02 = . if z02 > 5
rename z02 pray

///Sharia Law
replace z03 = 0 if z03 > 4
rename z03 Sharia

///Education 
replace z04 = . if z04 > 8
rename z04 education

///Occupation
replace z05 = . if z05 > 8
rename z05 occupation
gen unemployed = . 
replace unemployed = 1 if occupation == 1 
replace unemployed = 0 if occupation > 1 

///Household Income 
replace z06 = . if z06 > 10
rename z06 income 

///Gender
replace cins = 0 if cins == 2
rename cins male

///Age
gen age = . 
replace age = 2017 - dtarih

///About the Survey
gen yanliz = .
replace yanliz = 0 if t03 == 2
replace yanliz = 1 if t03 == 1

///Media ve Politics
replace e0301 = . if e0301 > 7
rename e0301 gazete
replace e0302 = . if e0302 > 7
rename e0302 TV
replace e0303 = . if e0303 > 7
rename e0303 socialmedia

///factor analysis
factor gazete TV socialmedia
screeplot, yline(1)

factor gazete TV socialmedia, mineigen(1)

predict f1
alpha gazete TV socialmedia

rename f1 politicalawareness

***Factor DV***
factor immthreat1 immthreat2 immthreat3 immpol1 immpol2 immpol3, pcf 
rotate, varimax
predict immigthreatfacall immigpolicyfacall 

***Index DV***
gen immigthreatsum=immthreat1+immthreat2+immthreat3
gen immigpolicysum=immpol1+immpol2+immpol3

*Analysis*
lab var employed "Employed"
lab var selfdiscrimination "Discriminated"
lab var newspaper "Newspaper"
lab var tv "TV"
lab var kurd "Kurd"
lab var socmedia "Social Media"
lab var turk "Turk"
lab var egocentsatis "Egocentric Evaluation"
lab var sociotrop "Sociotropic Evaluation"
lab var alone "Interviewed Alone"
lab var age "Age"
lab var male "Male"
lab var education "Education"
lab var income "Income"
lab var urban "Urban"
lab var religious "Religiosity"
lab var istanbul "Istanbul"
lab var diyarbakir "Diyarbakir"
lab var antep "Gaziantep"
lab var natidprio "Prioritize National ID"
lab var relidprio "Prioritize Religious ID"
lab var ethidprio "Prioritize Ethnic ID"
lab var immigthreatfacall "Perceived Threat (factor)"
lab var immigthreatsum "Perceived Threat (additive)"
lab var immigpolicyfacall "Demand for Integration (factor)"
lab var immigpolicysum "Demand for Integration (additive)"
lab var immthreat1 "Nat. Sec."
lab var immthreat2 "Econ. Sec."
lab var immthreat3 "Soc. Sec."
lab var immpol1 "Open Border"
lab var immpol2 "Work Permit"
lab var immpol3 "Citizsenship"

sutex immthreat1 immthreat2 immthreat3 immpol1 immpol2 immpol3 immigpolicyfacall immigpolicysum immigthreatfacall immigthreatsum relidprio natidprio antep istanbul diyarbakir kurd selfdiscrimination male employed income urban age education religious egocentsatis sociotrop alone, digits(3) lab nobs minmax title("Summary statistics")

***Hypo 1-2
eststo m1:reg immigthreatfacall natidprio, robust
eststo m2:reg immigthreatfacall natidprio kurd selfdiscrimination male employed urban age education religious egocentsatis sociotrop alone, robust
eststo m3:reg immigthreatfacall natidprio kurd selfdiscrimination male employed urban age education religious egocentsatis sociotrop alone antep istanbul, robust
eststo m4:reg immigthreatfacall relidprio, robust
eststo m5:reg immigthreatfacall relidprio kurd selfdiscrimination male employed urban age education religious egocentsatis sociotrop alone, robust
eststo m6:reg immigthreatfacall relidprio kurd selfdiscrimination male employed urban age education religious egocentsatis sociotrop alone antep istanbul, robust
esttab m1 m2 m3 m4 m5 m6 using "Table1_H1-2.tex", tex replace b(%10.3f) se scalars("r2 \$R^2\$") label starlevels(* 0.05 ** 0.01 *** 0.001) varlabels(_cons Constant)

***Hypo 3-4
eststo m1:reg immigpolicyfacall income, robust
eststo m2:reg immigpolicyfacall antep, robust
eststo m3:reg immigpolicyfacall istanbul diyarbakir, robust
eststo m4:reg immigpolicyfacall income antep kurd selfdiscrimination male employed urban age education religious egocentsatis sociotrop alone, robust
eststo m5:reg immigpolicyfacall c.antep##c.income kurd selfdiscrimination male employed urban age education religious egocentsatis sociotrop alone, robust
esttab m1 m2 m3 m4 m5 using "Table2_H3-4.tex", tex replace b(%10.3f) se scalars("r2 \$R^2\$") label starlevels(* 0.05 ** 0.01 *** 0.001) varlabels(_cons Constant)

reg immigpolicyfacall c.antep##c.income kurd selfdiscrimination male employed urban age education religious egocentsatis sociotrop alone, robust
margins, at(income=(1 10) antep=(0 1)) vsquish
marginsplot, x(income) recast(line) xlabel(1(3)10) level(95) 
